const commonCofig = require('./webpack.common.js');
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const path = require('path');

module.exports = merge(commonCofig, {
  mode: 'production',
  output: {
    filename: '[name]-[contenthash:8].js',
    path: path.join(__dirname, 'dist'),
  },
  devtool: false,
  optimization: {
    minimizer: [
      new TerserWebpackPlugin(),
      new OptimizeCssAssetsWebpackPlugin(),
    ],
    splitChunks: {
      chunks: 'all'
    }
  },
  plugins: [
    new CleanWebpackPlugin(),
    new MiniCssExtractPlugin({
      filename: 'style-[contenthash:8].css'
    }),
    new HtmlWebpackPlugin({
      title: '吴博的webpack',
      template: './public/index.html',
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
      },
    }),
    new CopyPlugin({
      patterns: [
        { from: 'public/favicon.ico', to: '.' },
      ],
    }),
  ]
})